# pluto/alg Makefile
# Author: JuanJo Ciarlante <jjo-ipsec@mendoza.gov.ar>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2 of the License, or (at your
# option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
#
# Makefile,v 1.1.2.1 2003/11/21 18:12:23 jjo Exp

Make.common: ../Makefile
	make --no-print-directory -s -C .. showdefs > $@

-include Make.common
include Config.ike_alg

ALLFLAGS=$(CPPFLAGS) $(CFLAGS) -I..  -I${OPENSWANDIR}/linux/include
LIBALG := libalg.o

all : $(LIBALG)

include $(wildcard Makefile.ike_alg_*)
#include $(wildcard Makefile.ike_alg_[ab]*)

ALG_DIRS:=$(ALG_DIRS-y)
ALG_LIBS:=$(ALG_LIBS-y)
ALG_SRCS:=$(ALG_SRCS-y)
ALG_OBJS:=$(ALG_OBJS-y)
$(LIBALG): ike_alginit.o $(ALG_OBJS) $(ALG_LIBS) 
	$(LD) -r -o $@ $^

# Search for IKE_ALG_INIT_NAME: in ike_alg_*.c to
# build ike_alginit.c:ike_alginit()

ike_alginit.c: $(ALG_SRCS) Makefile Config.ike_alg
	@awk '	\
		BEGIN { print "extern int ike_alg_init(void); \
			int ike_alg_init(void) {" } \
		/IKE_ALG_INIT_NAME:/ \
			{ print "{ extern int " $$2" (void); " $$2 "();}" } \
		END   { print "return 0;}" } \
		' $(ALG_SRCS) /dev/null > $@ 

clean :
	@for i in $(ALG_DIRS);do make -C $$i clean;done
	rm -f *.[oa] ike_alginit.c Make.common

gatherdeps:
	@ls $(ALG_SRCS) | grep '\.c' | sed -e 's/\(.*\)\.c$$/\1.o: \1.c/'
	@echo
	@ls $(ALG_SRCS) | grep '\.c' | xargs grep '^#[ 	]*include[ 	]*"' | \
		sed -n -e '/#include.*"lib/d' \
		-e 's/\.c:#[ 	]*include[ 	]*"/.o: ..\//' -e 's/".*//p'

# Dependencies generated by "make gatherdeps":

ike_alg_aes.o: ike_alg_aes.c
ike_alg_blowfish.o: ike_alg_blowfish.c
ike_alg_twofish.o: ike_alg_twofish.c
ike_alg_sha2.o: ike_alg_sha2.c

ike_alg_aes.o: ../md5.h
ike_alg_aes.o: ../sha1.h
ike_alg_aes.o: ../constants.h
ike_alg_aes.o: ../defs.h
ike_alg_aes.o: ../state.h
ike_alg_aes.o: ../log.h
ike_alg_aes.o: ../crypto.h
ike_alg_aes.o: ../alg_info.h
ike_alg_aes.o: ../ike_alg.h
ike_alg_blowfish.o: ../constants.h
ike_alg_blowfish.o: ../defs.h
ike_alg_blowfish.o: ../log.h
ike_alg_blowfish.o: ../alg_info.h
ike_alg_blowfish.o: ../ike_alg.h
ike_alg_twofish.o: ../constants.h
ike_alg_twofish.o: ../defs.h
ike_alg_twofish.o: ../log.h
ike_alg_twofish.o: ../alg_info.h
ike_alg_twofish.o: ../ike_alg.h
ike_alg_serpent.o: ../constants.h
ike_alg_serpent.o: ../defs.h
ike_alg_serpent.o: ../log.h
ike_alg_serpent.o: ../alg_info.h
ike_alg_serpent.o: ../ike_alg.h
ike_alg_sha2.o: ../constants.h
ike_alg_sha2.o: ../defs.h
ike_alg_sha2.o: ../log.h
ike_alg_sha2.o: ../alg_info.h
ike_alg_sha2.o: ../ike_alg.h

